<template>
  <div class="news" v-loading.fullscreen.lock="loading">
    <div class="item">
      <div class="content">
        <router-view />
      </div>
      <div class="item-bot">
        <div style="margin-bottom: 30px;">最新推荐</div>
        <div style="display: flex;">
          <div class="for" v-for="(item, index) in galleryData" :key="index"  @click="goRouter(item)">
            <img :src="item.img_list[0].response" alt />
            <div style="font-size: 14px;margin-top: 10px;">{{item.name}}</div>
            <div class="for-icon">
              <div>
                <i></i>
                <span>{{item.time}}</span>
              </div>
              <div>
                <i></i>
                <span>{{item.views}}</span>
              </div>

              <div>
                <i></i>
                <span>{{item.collect}}</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="news-right">
      <div>推荐阅读</div>
      <div>
        <div
          class="suggest"
          v-for="(item, index) in collectData"
          :key="index"
          @click="goRouter(item)"
        >
          <img :src="item.img_list[0].response" alt="暂时无法显示" />
          <div>{{item.name}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { galleryListCollect, galleryList,galleryAddViews } from "@/api/home/api";
export default {
  data() {
    return {
        loading:false,
      collectData: [],
      galleryData: []
    };
  },
  created() {
    this.galleryListCollect();
    this.getList();
  },
  methods: {
    galleryListCollect() {
      galleryListCollect().then(res => {
        let data = res.data;

        data.dataList.forEach((item, index, arr) => {
          arr[index].img_list = JSON.parse(arr[index].img_list);
        });
        this.collectData = data.dataList;
      });
    },
    getList() {
      let query = {
        address: "",
        current: 1,
        name: "",
        size: 3,
        type_id: ""
      };
      galleryList(query).then(res => {
        let data = res.data;
        data.dataList.forEach((item, index, arr) => {
          arr[index].img_list = JSON.parse(arr[index].img_list);
        });
        this.galleryData = data.dataList;
      });
    },
    goRouter({ id }) {
        this.loading=true
      galleryAddViews({ id }).then(res => {
        let data = res.data;
        data.dataList.forEach((item, index, arr) => {
          arr[index].img_list = JSON.parse(arr[index].img_list);
        });
        let galleryData=JSON.stringify(data.dataList[0])
         this.loading=false
        this. $router.push({ path: '/home/news/img',query: { galleryData } })
      });
    }
  }
};
</script>

<style scoped>
.news {
  display: flex;
}
.item {
  width: 72%;
}
.content {
  width: 100%;
}
.item-bot {
  font-size: 18px;
  font-weight: bold;
  margin-top: 20px;
}
.news-right {
  width: 28%;
}
.news-right img {
  width: 100%;
  height: 174px;
}
.news-right > div:first-child {
  box-sizing: border-box;
  width: 100%;
  background: #000;
  padding: 15px 0 15px 25px;
  color: #ecedee;
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 20px;
}
.news-right > div:last-child {
  width: 100%;
}
.suggest {
  margin-bottom: 45px;
  position: relative;
  display: flex;
  justify-content: center;
  cursor: pointer;
}
.suggest > div {
  position: absolute;
  bottom: -10%;
  padding: 10px;
  font-size: 16px;
  color: #fff;
  opacity: 0.8;
  background: #0ec5a1;
  text-align: center;
}
.for {
  margin-right: 18px;
  cursor: pointer;
}
.for img {
  width: 258px;
  height: 132px;
}
.for-icon {
  display: flex;
}
.for-icon {
  height: 20px;
  color: #b2b1b1;
  font-size: 12px;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 6px;
  padding-top: 8px;
  cursor: pointer;
}
.for-icon > div {
  margin-right: 20px;
  
}

.for-icon > div:nth-child(1) > i {
  padding: 2px 12px;
  margin-right: 4px;
  background: url("../../../assets/icon/spirit.png") 0 -266px;
}
.for-icon > div:nth-child(2) > i {
  padding: 2px 12px;
  margin-right: 4px;
  background: url("../../../assets/icon/spirit.png") 0 -173px;
}
.for-icon > div:last-child > i {
  padding: 2px 12px;
  margin-right: 4px;
  background: url("../../../assets/icon/spirit.png") 0 -216px;
}
</style>